package com.electron.power.aio.mod.client;

import org.smartboot.socket.transport.AioQuickClient;
import org.smartboot.socket.transport.AioSession;
import org.smartboot.socket.transport.WriteBuffer;

import com.electron.power.common.Coding;
import com.electron.power.model.mod.ModBodyMap;
import com.electron.power.model.mod.ModStr;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ModClient {
	public static void main(String[] args) {
		AioQuickClient<String> aioQuickClient = null;
		try {
			ModClientProcessor processor = new ModClientProcessor();
//			String host = "47.106.76.180";
			String host = "127.0.0.1";
			aioQuickClient = new AioQuickClient<String>(host, 8888, new ClientStrProtocol(), processor);
			AioSession<String> session = aioQuickClient.start();
			ModStr mod = new ModStr();
//			String orignData = "550300661A2B3C4D5E800000000000000000000000000000000A000003E70000000900000C99000013880000000000000000000000000000000A000003E70000000900000C80000013880000000000000000000000000000000A000003E70000000900000C03000013880529";
			String orignData = "550300661A2B3C4D6280003AF5C000002DDD0000A7F80000174800000009000017360000121100001384003B28880000275D0033ECF80000F938000003690000F878000011DF00001384003B0D3000002BA40034F2B00000E4D4000003230000E4240000113000001384A072";
							
			log.info("orignData length is:{}",orignData.length());
			WriteBuffer writeBuffer = session.writeBuffer();
			byte[] hex2byte = Coding.hex2byte(orignData.getBytes());
			log.info("hex2byte length is:{}",hex2byte.length);
			writeBuffer.write(hex2byte);
			writeBuffer.flush();
			Thread.sleep(3000);
		} catch (Exception e) {
			log.error("客户端发送消息错误", e);
		} finally {
			if (aioQuickClient != null) {
				aioQuickClient.shutdown();
			}
		}

	}
}
